const express = require('express');
const app=express();
const path=require('path');
const fs=require('fs');
// const cookieParser=require('cookie-parser');
// app.use(cookieParser());

var privateKey = fs.readFileSync(path.join(__dirname, './certificate/private.pem'), 'utf8'); 
var certificate = fs.readFileSync(path.join(__dirname, './certificate/file.crt'), 'utf8'); 
var credentials = {key: privateKey, cert: certificate};
const server = require('https').createServer(credentials,app);
const io = require('socket.io').listen(server);

 

app.use('/public', express.static('public'));
server.listen(443);

app.get('/', function (req, res) {
  res.sendFile(__dirname + '/views/index.html');
});
app.get('/video', function (req, res) {
  res.sendFile(__dirname + '/views/jsVideo.html');
});

io.sockets.on('connection', function (socket) {
  // socket.emit('msgs', { serverMsg: 'world' });
  //   console.log(socket)
  socket.on('send', function (data) {
    console.log(data);
    io.emit('msgs', {name:data.name, serverMsg: data.msg });
  });
  socket.on('sendVideo', function (data) {
    console.log(data);
    io.emit('video', data);
  });
});
